`
https://leetcode.cn/problems/longest-absolute-file-path/
`

/**
 * @param {string} input
 * @return {number}
 */
var lengthLongestPath = function (input) {
  const stk = []
  let maxLen = 0
  const parts = input.split('\n')
  for (const part of parts) {
    // 计算层级
    const level = part.lastIndexOf('\t') + 1
    // 让栈中只保留当前目录的父路径
    while (level < stk.length) {
      stk.pop()
    }
    // 放入栈
    stk.push(part.substring(level))
    // 如果是文件，就计算路径长度
    if (part.includes(".")) {
      let sum = stk.reduce((acc, val) => acc + val.length, 0);
      // 加上父路径的分隔符
      sum += stk.length - 1;
      maxLen = Math.max(maxLen, sum);
    }
  }
  return maxLen
};